/**
 * 商品 spu 相关
 */
import service from "@/utils/request"
import type { spuResponse, spuItemModel, spuImageListModel, spuBaseSaleAttrListModel, spuSaleAttrListModel, spuTrademarkListModel } from './model/spu'

enum API {
  // 获取 SPU 列表
  getSpuList = '/admin/product',
  // 添加SPU对象
  saveSpuInfo = '/admin/product/saveSpuInfo',
  // 更新 SPU 对象
  updateSpuInfo = '/admin/product/updateSpuInfo',

  // 获取 trademark
  getBaseTrademarkList = '/admin/product/baseTrademark/getTrademarkList',

  // 获取销售属性列表
  getBaseSaleAttrList = '/admin/product/baseSaleAttrList',

  // 获取 SPU 图片列表
  getSpuImageList = '/admin/product/spuImageList',
  // 获取 spu 销售属性
  getSpuSaleAttrList = '/admin/product/spuSaleAttrList',
  // 保存 spu
  saveSkuInfo = '/admin/product/saveSkuInfo',
  // 删除 spu
  deleteSpuInfo = '/admin/product/deleteSpu'
}

// 获取 SPU 列表
export const reqGetSpuList = (page: number, limit: number, category3Id: number) => service.get<any, spuResponse>(`${API.getSpuList}/${page}/${limit}`, {
  params: {
    category3Id
  }
})

// 获取 trademark
export const reqGetBaseTrademarkList = () => service.get<any, spuTrademarkListModel>(API.getBaseTrademarkList)

// 获取销售属性列表
export const reqGetBaseSaleAttrList = () => service.get<any, spuBaseSaleAttrListModel>(API.getBaseSaleAttrList)

// 获取 SPU 图片列表
export const reqGetSpuImageList = (spuId: number) => service.get<any, spuImageListModel>(`${API.getSpuImageList}/${spuId}`)
// 获取 spu 销售属性
export const reqGetSpuSaleAttrList = (spuId: number) => service.get<any, spuSaleAttrListModel>(`${API.getSpuSaleAttrList}/${spuId}`)
// 添加 spu
export const reqSaveSpuInfo = (spuInfo: spuItemModel) => service.post(API.saveSpuInfo, spuInfo)

// 更新 spu
export const reqUpdateSpuInfo = (spuInfo: spuItemModel) => service.post(API.updateSpuInfo, spuInfo)

// 删除 spu
export const reqDeleteSpuInfo = (spuId: number) => service.delete(`${API.deleteSpuInfo}/${spuId}`)
// 添加 sku
// export const reqSaveSkuInfo = (params) => service.post(API.saveSkuInfo, params)
